import * as mobx from 'mobx';
import { observable, action, useStrict, computed, asMap } from 'mobx';
import { overTimeSetting } from '../apis/req';
import { message, Modal } from 'antd'

import { getLabel } from '../util/convert';
import * as Util from './../util/formUtil';
import { requestWithDraw } from '../apis/req';

export class RequestWithdrawStore {

    @observable loading = true;
    baseParams = {};
    allowRemind = '';
    isRemind = '1';
    recallNodeId = "";
    recallNodeName = "";
    doPreOperate = "";
    lastOperateTime = "";
    lastOperateDate = "";
    currentdate = "";
    currenttime = "";
    closeEvent = function () { };

    constructor() {
        this.doInit = this.doInit;
        this.doSubmit = this.doSubmit;
        this.setCloseEvent = this.setCloseEvent;
        this.setIsRemind = this.setIsRemind;
    }

    @action
    doInit = (params = {})  => {
        this.baseParams = params;
        requestWithDraw({ ...this.baseParams, actionType: 'getSettings' }).then(data => {
            this.allowRemind = data.allowRemind;
            this.recallNodeId = data.recallNodeId;
            this.recallNodeName = data.recallNodeName;
            this.doPreOperate = data.doPreOperate;
            this.loading = false;
        });
    }

    doSubmit = (remark = '') =>  {
        this.loading = true;
        message.loading(getLabel(515991, '撤回中...，请稍候'), 0);
        let submitParams = {actionType: 'submit','isRemind':this.isRemind,'remark':remark,'recallNodeId':this.recallNodeId,
            'doPreOperate':this.doPreOperate,'lastOperateDate':this.lastOperateDate,'lastOperateTime':this.lastOperateTime,
            'currentdate':this.currentdate,'currenttime':this.currenttime};
        requestWithDraw({ ...this.baseParams, ...submitParams}).then(data => {
            message.destroy();
            let msg = data.msg;
            if (data.result == "success") {
                message.success(msg);
                this.closeEvent();
                Util.reloadRequestPage({ ...this.baseParams });
            } else {
                message.error(msg);
            }
            this.loading = false;
        });
    }

    setCloseEvent = (fun)  => {
        this.closeEvent = fun;
    }

    setIsRemind = (isRemind)  => {
        this.isRemind = isRemind;
    }

    @action('修改store中的属性')
    setState = (state = {}) => {
        const { toJS } = mobx;
        console.log("state",state);
        const keys = Object.keys(state);
        keys.forEach(key => {
            this[key] = state[key];
        })
    }


}